<template>
  <div :class="{ 'bottom-tab-item': true, selected: tab.active }" :style="{ flexBasis: width }">
    <img v-if="showDark" :src="getIcon(tab, 'dark')" alt="" class="icon" />
    <img v-if="!showDark" :src="getIcon(tab, 'normal')" alt="" class="icon" />
    <span>{{ tab.tabName }}</span>
  </div>
</template>

<script setup lang="ts">
import { Tab } from '@/types/home.d';
interface Props {
  tab: Tab;
  width: string;
}

withDefaults(defineProps<Props>(), {});

const getIcon = (tab: Tab, mode: 'normal' | 'dark') => {
  let result = '';
  if (mode === 'normal') {
    result = tab.active ? tab.tabSelectedIcon : tab.tabNormalIcon;
  } else {
    result = tab.active ? tab.tabDarkSelectedIcon : tab.tabDarkNormalIcon;
  }
  if (result.includes('//')) {
    return result;
  } else {
    return new URL(`../../assets/images/${result}.png`, import.meta.url).href;
  }
};
const showDark = window.getCssStyle() === 'black';
</script>

<style lang="less">
.bottom-tab-item {
  height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: var(--bg-color-1);
  font-size: 12px;
  font-family: PingFangSC-Regular;
  color:var(--color-2);
  &.selected {
    span {
      color: var(--color-1);
    }
  }
  img.icon {
    width: 24px;
    height: 24px;
  }
}
</style>
